package com.lee.study;


import dev.langchain4j.data.embedding.Embedding;
import dev.langchain4j.data.segment.TextSegment;
import dev.langchain4j.model.embedding.EmbeddingModel;
import dev.langchain4j.model.ollama.OllamaEmbeddingModel;

import java.util.List;

public class EmbeddingService {
    private final EmbeddingModel model;

    public EmbeddingService(String baseUrl, String modelName) {
        this.model = OllamaEmbeddingModel.builder()
                .baseUrl(baseUrl)
                .modelName(modelName) // 如 nomic-embed-text
                .build();
    }

    public List<Embedding> embed(List<TextSegment> segments) {
        return model.embedAll(segments).content();
    }

    public Embedding embed(String text) {
        return model.embed(text).content();
    }
}
